#include <vector>

using std::vector;

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        vector<int> v(digits);
        int i = digits.size() - 1;
        int jin = 1;
        while (i >= 0) {
            int tmp = digits[i] + jin;
            if (tmp <= 9) {
                v[i] = tmp;
                jin = 0;
            }
            else {
                v[i] = 0;
                jin = 1;
            }
            i--;
        }
        if (jin == 1) {
            v = vector<int>(digits.size() + 1, 0);
            v[0] = 1;
        }
        return v;
    }
};